using System;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;
using FrameIdentityReq.Frames;

namespace xUnitTest
{
    public class TestBytesExtention
    {
        const byte DLE = 0xfe;    // DLE STX 帧头 DLE ETX 帧尾 数据中有DLE,使用DLE DLE替代

        private readonly ITestOutputHelper Output;


        public TestBytesExtention(ITestOutputHelper output)
        {
            Output = output;
        }

        [Theory]
        [InlineData(new byte[] { 1, 2, DLE, 3, 4 }, new byte[] { 1, 2, DLE, DLE, 3, 4 }, new byte[] { 1, 2, DLE, 3, 4, 0 })]
        [InlineData(new byte[] { 1, 2, DLE, DLE, 3, 4 }, new byte[] { 1, 2, DLE, DLE, DLE, DLE, 3, 4 }, new byte[] { 1, 2, DLE, DLE, 3, 4, 0, 0 })]
        [InlineData(new byte[] { DLE, DLE, 3, 4 }, new byte[] { DLE, DLE, DLE, DLE, 3, 4 }, new byte[] { DLE, DLE, 3, 4, 0, 0 })]
        [InlineData(new byte[] { 1, 2, DLE, DLE }, new byte[] { 1, 2, DLE, DLE, DLE, DLE }, new byte[] { 0, 2, DLE, DLE })]
        public void TestDuplicateDle(IList<byte> source, IList<byte> target, IList<byte> flaseTarget)
        {
            Assert.Equal(target.Count, source.ToList().DuplicateDle().Count);
            Assert.Equal(target, source.ToList().DuplicateDle());
            Assert.NotEqual(flaseTarget, source.ToList().DuplicateDle());
        }

        [Theory]
        [InlineData(new byte[] { 1, 2, DLE, DLE, DLE, DLE }, new byte[] { 1, 2, DLE, DLE }, new byte[] { 0, 2, DLE, DLE })]
        [InlineData(new byte[] { DLE, DLE, DLE, DLE, 3, 4 }, new byte[] { DLE, DLE, 3, 4 }, new byte[] { DLE, DLE, 3, 0 })]
        [InlineData(new byte[] { 1, 2, DLE, DLE, DLE, DLE, 3, 4 }, new byte[] { 1, 2, DLE, DLE, 3, 4 }, new byte[] { 1, 2, DLE, DLE, 3, 0 })]
        [InlineData(new byte[] { 1, 2, DLE, DLE, DLE, 3, 4 }, new byte[] { 1, 2, DLE, DLE, 3, 4 }, new byte[] { 1, 2, DLE, DLE, 3, 0 })]
        [InlineData(new byte[] { 1, 2, DLE, DLE, 3, 4 }, new byte[] { 1, 2, DLE, 3, 4 }, new byte[] { 1, 2, DLE, 3, 0 })]
        [InlineData(new byte[] { 1, 2, DLE, 3, 4 }, new byte[] { 1, 2, DLE, 3, 4 }, new byte[] { 1, 2, DLE, 3, 0 })]
        public void TestRemoveDuplicateDle(IList<byte> source, IList<byte> target, IList<byte> flaseTarget)
        {
            Assert.Equal(target.Count, source.ToList().RemoveDuplicateDle().Count);
            Assert.Equal(target, source.ToList().RemoveDuplicateDle());
            Assert.NotEqual(flaseTarget, source.ToList().RemoveDuplicateDle());
        }
    }
}